/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mapcontrol.maplisteners;

import imgparser.ImgFileBag;
import imgparser.labels.Label;
import imgparser.SubDivision;
import mapcontrol.MapConfig;
import mapcontrol.ImgConstants;

/**
 *
 * @author Pieter
 */
public class MapFilter implements MapListener {

    private MapListener next;
    private MapConfig config;

    public MapFilter(MapConfig config, MapListener next) {
        this.next = next;
        this.config = config;
    }

    public void addPoint(int type, int subType, int longitude, int latitude, Label label, boolean indexed) {
        if (ImgConstants.isPOI(type, subType)) {
            if (config.isShowPOIs()) {
                next.addPoint(type, subType, longitude, latitude, label, indexed);
            }
        } else {
            if (config.isShowCitiesAndTowns()) {
                next.addPoint(type, subType, longitude, latitude, label, indexed);
            }

        }
    }

    public void addPoly(int type, int[] longitudes, int[] latitudes, int nbPoints, Label label, boolean line, boolean direction) {
        if (line) {
            if (ImgConstants.isPavedRoad(type)) {
                if (config.isShowPavedRoads()) {
                    next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
                }
            } else if (ImgConstants.isUnPavedRoad(type)) {
                if (config.isShowUnpavedRoads()) {
                    next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
                }
            } else if (ImgConstants.isWaterLine(type)) {
                if (config.isShowWaterLines()) {
                    next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
                }
            } else if (ImgConstants.isTopoLine(type)) {
                if (config.isShowTopoLines()) {
                    next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
                }
            } else {
                if (config.isShowOtherLines()) {
                    next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
                }
            }

        } else {
            if (config.isShowPolygons() || type == ImgConstants.BACKGROUND) {
                next.addPoly(type, longitudes, latitudes, nbPoints, label, line, direction);
            }
        }
    }

    public void startMap(ImgFileBag file) {
        next.startMap(file);
    }

    public void startSubDivision(SubDivision subDivision) {
        next.startSubDivision(subDivision);
    }

    public void finishPainting() {
        next.finishPainting();
    }
}
